﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 坦克大战
{
    public partial class Form1 : Form
    {
        Thread t;
      private static Bitmap  临时图片;
        private static Graphics 窗体画布 ;
        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            //阻塞


            窗体画布 = this.CreateGraphics();

            临时图片 = new Bitmap(450,450);
            Graphics 临时画布 = Graphics.FromImage(临时图片);
            游戏框架.g = 临时画布;
             t = new Thread(new ThreadStart(开始携程));
            t.Start();

        }
        private static void 开始携程()
        {
            游戏框架.Start();
            int 游戏帧率时间 = 1000 / 60;
            while (true)
            {
                游戏框架.g.Clear(Color.Black);
                游戏框架.Update();
                窗体画布.DrawImage(临时图片,0,0);
                Thread.Sleep(游戏帧率时间);
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            t.Abort();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            游戏管理者.按键按下(e);

        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            游戏管理者.按键抬起(e);
        }
    }
}
